package ioc16;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/5/17 15:09
 * Version:1.0-SNAPSHOT
 * Description:
 */
public class DateEditorSupport extends PropertyEditorSupport {

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        try {
            Date date = new SimpleDateFormat("yyyy-MM-dd").parse(text);
            setValue(date);
        } catch (ParseException e) {
            throw new IllegalArgumentException("日期格式不对,格式必须为:yyyy-MM-dd");
        }
    }
}
